package com.ltt.controller;

import com.ltt.annotation.NoAuth;
import com.ltt.dao.pojo.Cereals;
import com.ltt.dao.pojo.Crops;
import com.ltt.dao.vo.Result;
import com.ltt.dao.vo.findAllCropsById;
import com.ltt.service.CropsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ‘李天泰’
 * @version 1.0
 * @description: TODO
 * @date 2023/5/4 9:21
 */
@CrossOrigin
@Api(tags = "资源模块")
@RestController
@RequestMapping("/crops")
public class CropsController {
    @Autowired
    private CropsService cropsService;

    @NoAuth
    @ApiOperation("获取所有的作物，根据种类分类")
    @GetMapping("/getCereals")
    public Result findSeasonAndSolar() {
        List<Crops> allCrops = cropsService.findAllCrops();
        return Result.successWithData(allCrops);
    }

    @NoAuth
    @ApiOperation("通过名字搜索作物")
    @GetMapping("/getCerealsByName")
    public Result getCerealsByName(@RequestParam String name){
        List<Cereals> cropsByName = cropsService.findCropsByName(name);

        return Result.successWithData(cropsByName);
    }

    @ApiOperation("用户故事")
    @PostMapping("/getCerealsByOpenId")
    public Result findAllCropsByOpenId(@RequestBody String openid){
        List<findAllCropsById> cropsByName = cropsService.findAllCropsByOpenId(openid);

        return Result.successWithData(cropsByName);
    }

}
